package com.deadletter.customer;

import com.deadletter.config.MqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 死信消费者
 */
@Component
public class DeadCustomer {

    @RabbitListener(queues = MqConfig.DEAD_LETTER_QUEUEA_NAME)
    public void  bizCustomerA(Channel channel, Message message){

        String str = new String(message.getBody());

        System.out.println("--------死信消费者A----str-" + str);

        //进入死信队列
        try {
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,false);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


    @RabbitListener(queues = MqConfig.DEAD_LETTER_QUEUEB_NAME)
    public void  bizCustomerB(Channel channel, Message message){

        String str = new String(message.getBody());

        System.out.println("--------死信消费者B----str-" + str);


        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
